import { message } from "ant-design-vue";
import axios from "axios";
import { ErrorCode } from "./01errors.enum";
import { NetworkError } from "./02error.class";
import { errorMapping } from "./03error.mapper";



export function convertError(error: Error): Error {
  if (axios.isAxiosError(error)) {
    if (!error.response) {
      return new NetworkError(error.message);
    }
 
    
    const errorCode = error.response.status as ErrorCode;
    const ErrorClass = errorMapping[errorCode]  || Error;
    return new ErrorClass(error.response.data.message);
  }
  message.error(error.message);
  return error; // 如果不是axios错误，直接返回原错误
}